package Model.alignments;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;

import Control.Zoomable;
import Model.Subset;
import Model.ValidPosition;

public class SpliceAlignment extends SingleAlignment {

	public SpliceAlignment(int start, Subset sub, String cigarString) {
		super(start, 1, sub, cigarString);
	}

	@Override
	public void draw(Graphics graphic, int x, int y) {
		// Since it's a splice site alignment, the valid positions should be
		// more than 1.
		if (this.getValidPositions().size() <= 1)
			System.out.println("SpliceAlignment size is off: "
					+ this.getValidPositions().size());

		Color color = this.getParent().getTreatmentParent().getColor();
		Graphics2D g2d = (Graphics2D) graphic;
		Zoomable z = Zoomable.getInstance();

		int oldOffset = 0;
		for (ValidPosition vp : getValidPositions()) {
			g2d.setColor(color);
			vp.x = x + z.calcDist(vp.start);
			vp.y = y;
			vp.width = z.calcDist(vp.getDistance());
			vp.height = 4;
			g2d.fill(vp);
			g2d.setColor(new Color(100, 100, 100));
			g2d.draw(vp);
			if (oldOffset != 0) {
				g2d.drawLine(oldOffset, y + 2, x + z.calcDist(vp.start), y + 2);
			}
			oldOffset = x + z.calcDist(vp.end);
		}
	}

	@Override
	public String toString() {
		return "Splice Alignment";
	}
}
